const app = getApp()

const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
var t = getApp(), e = t.requirejs("core"), a = t.requirejs("foxui"), i = t.requirejs("biz/diyform"), n = t.requirejs("jquery");

Page({
  data: {
    avatarUrl: defaultAvatarUrl,
    theme: wx.getSystemInfoSync().theme,
    submit: !1,
    username:'微信用户',
    id:0
  },
  onLoad(e) {
    console.log(e.id)
    wx.onThemeChange((result) => {
      this.setData({
        theme: result.theme,
        id:e.id
      })
    })
  },
  onChooseAvatar(e) {
    const { avatarUrl } = e.detail 
    t=this;
        // const tempFilePaths = e.detail 
        wx.uploadFile({
          url: 'https://shangcheng.skspmall.com/app/ewei_shopv2_api.php?i=4&r=util.uploader.upload', //仅为示例，非真实的接口地址
          filePath: e.detail.avatarUrl ,
          name: 'file',
          formData: {
            'user': 'test'
          },
          success (res){
            // console.log(res.data)
            
            const rdata = JSON.parse(res.data);
            console.log(rdata.files[0].url)
            t.setData({
              avatarUrl:rdata.files[0].url
            })
            //do something
          },
          fail(res){
            console.log(e.detail)
          }
        })
   
 

  },
  onChange: function(t) {
     console.log(t)
     this.setData({
      username:t.detail.value,
    })
     
},
  submit: function() {
    console.log(this.data.submit)
     
      console.log(this.data)
      console.log(22)
      var s = {
        id: this.data.id,
        touxiang:this.data.avatarUrl,
        username:this.data.username
    }
    t=this;
      e.post("member/info/submits", s, function(e) {
        0 == e.error ? (t.setData({
            submit: !1
        }), a.toast(t, "修改成功"), setTimeout(function() {
            wx.navigateBack();
        }, 500)) : a.toast(t, e.message);
    });
  }
})
